﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Moq;
using Polar.AI.Common;
using FarseerPhysics;
using Polar.AI.Analysis;

namespace Polar.AI.Tests
{
    public static class TestHelper
    {
        public static ThreatAnalysis BuildGenericThreat(Vector2 x1, Vector2 lx, Vector2 y1, Vector2 ly)
        {
            Mock<IBody> b1 = BuildBodyMock(x1, lx);
            Mock<IBody> b2 = BuildBodyMock(y1, ly);

            return new ThreatAnalysis(b1.Object, b2.Object);
        }

        public static IBody BuildBody(Vector2 position, Vector2 velosity)
        {
            return BuildBodyMock(position, velosity).Object;
        }

        public static Mock<IBody> BuildBodyMock(Vector2 position, Vector2 velosity)
        {
            Mock<IBody> b1 = new Mock<IBody>();

            b1.SetupProperty(x => x.Position, position).SetupProperty(x => x.LinearVelocity, velosity).Setup(x => x.Radius).Returns(2.0f);

            b1.Setup(x => x.Forward()).Returns(Forward(b1.Object));

            b1.Setup(x => x.Direction()).Returns(Direction(b1.Object));

            return b1;
        }

        #region Private Methods...
        private static float Direction(IBody body)
        {
            if (body.LinearVelocity.IsZero())
                return 0;
            else
                return body.LinearVelocity.ToRadians();
        }

        private static Vector2 Forward(IBody body)
        {
            if (body.LinearVelocity.IsZero())
                return Vector2.Zero;
            else
                return Vector2.Normalize(body.LinearVelocity);
        } 
        #endregion
    }
}
